package zhouzhouyongche.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import zhouzhouyongche.client_util.ClientCity;
import zhouzhouyongche.dao.CityDao;
import zhouzhouyongche.model.City;
import zhouzhouyongche.service.CityService;

@Service
public class CityServiceImpl implements CityService{

	@Autowired
	private CityDao cityDao;
	
	@Override
	public List<ClientCity> getCities() {
		List list = cityDao.getCities();
		List<ClientCity> resultList = transformat(list);
		return resultList;
	}

	private List<ClientCity> transformat(List list) {
		List<ClientCity> resultList = new ArrayList<ClientCity>();
		for(int i = 0; i < list.size(); i++){
			ClientCity clientCity = new ClientCity();
			Object[] objs = (Object[])list.get(i);
			
			clientCity.setId((int)objs[0]);
			clientCity.setCityName((String)objs[1]);
			
			resultList.add(clientCity);
		}
		return resultList;
	}

	@Override
	public void addCity(String cityName) {
		cityDao.addCity(cityName);
	}

	@Override
	public void editCity(int cityId, String cityName) {
		cityDao.editCity(cityId, cityName);
	}

	@Override
	public void deleteCity(int cityId) {
		cityDao.deleteCity(cityId);
	}
}
